//
//  ResetModel.m
//  MUBATE
//
//  Created by sunbin on 2017/2/16.
//  Copyright © 2017年 Quanli. All rights reserved.
//

#import "ResetModel.h"

@implementation ResetModel
+ (void)resetHandle:(resetHandle)handle handleValue:(NSString *)value handleAccount:(NSString *)account accountTy:(accountType)ty success:(void (^)(NSDictionary * loginresults, NSString* loginRequestmsg))loginSuccess
            failure:(void (^)(NSDictionary * loginresults, responseState resMake, NSString* loginRequestError))loginFailed{


    NSDictionary *parameters = [self getResetHandle:handle handleValue:value handleAccount:account accountTy:ty];
    
    [ZL_NetworkHelper POST:ty==EmailTYpe?EMAILRESETPWD:PHONERESETPWD parameters:parameters success:^(id responseObject) {
        NSDictionary *dic = (NSDictionary *)responseObject;
        
        NSString *res = IF_NULL_TO_STRING([dic objectForKey:@"res"]);
        NSString *msg = IF_NULL_TO_STRING([dic objectForKey:@"msg"]);
        NSLog(@"%@" ,dic);
        if ([res isEqualToString:@"1"]) {
            loginSuccess(dic ,msg);
        }else{
            loginFailed(nil , Error ,msg);
        }
    } failure:^(NSError *error) {
        loginFailed(nil , Failure ,error.localizedDescription);
    }];



}


+ (NSDictionary *)getResetHandle:(resetHandle)handle handleValue:(NSString *)value handleAccount:(NSString *)account accountTy:(accountType)ty{
    NSDictionary *parameters;
    switch (handle) {
        case SenderCode:{
            parameters =ty==EmailTYpe?
            @{@"email":account ,@"send":@"1" ,@"sign":SIGN }:
            @{@"phone":account ,@"send":@"1" ,@"sign":SIGN };
        }
            
            break;
        case SubmitCode:{
            parameters =ty==EmailTYpe?
            @{@"email":account ,@"act":@"1" ,@"scode":value ,@"sign":SIGN }:
            @{@"phone":account ,@"act":@"1" ,@"scode":value ,@"sign":SIGN };
        }
            break;

        case ResetPwdOperate:{
            parameters =ty==EmailTYpe?
            @{@"email":account ,@"newpwd":[value md5String] ,@"pwd":value ,@"sign":SIGN }:
            @{@"phone":account ,@"newpwd":[value md5String] ,@"pwd":value ,@"sign":SIGN };
        }
            break;
        default:
            break;
    }
    return parameters;
    
}





@end
